package cn.xchats.demo.core.consumer;

import cn.xchats.demo.core.api.UserApi;
import cn.xchats.demo.core.dto.UserDto;
import cn.xchats.rpc.common.annotation.RpcReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/*
 *
 *@author teddy
 *@date 2018/7/10
 */
@RestController
public class UserController {

    @RpcReference
    private UserApi userApi;

    @RequestMapping(value = "testFlow")
    public boolean testFlow() {
        //test_1
        UserDto userDto_1 = new UserDto();
        userDto_1.setId("1");
        userDto_1.setName("name_1");
        userDto_1.setSex("sex_1");

        UserDto userDto_2 = new UserDto();
        userDto_2.setId("2");
        userDto_2.setName("name_2");
        userDto_2.setSex("sex_2");

        userApi.createUser(userDto_1);
        userApi.createUser(userDto_2);

        //test_2
        UserDto user_result_1 = userApi.getUser(userDto_1.getId());
        UserDto user_result_2 = userApi.getUser(userDto_2.getId());

        //test_3
        List<UserDto> user_list_result_1 = userApi.listUser();
        List<UserDto> user_list_result_2 = userApi.listUser();
        return true;
    }
}
